/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.main;

import com.alipay.sofa.rpc.config.ConsumerConfig;
import com.alipay.sofa.rpc.config.RegistryConfig;
import com.example.service.HelloService;

/**
 * <p></p>
 *
 * Created by zhangg on 2018/4/13 10:25. <br/>
 *
 * @author <a href=mailto:zhanggeng@howtimeflies.org>GengZhang</a>
 */
public class SofaRpcClientMain {

    public static void main(String[] args) {
        // 指定注册中心
        RegistryConfig registryConfig = new RegistryConfig()
                .setProtocol("zookeeper")
                .setAddress("127.0.0.1:2181");
        
        RegistryConfig registryConfigLocal = new RegistryConfig()
    	         .setProtocol("local")
    	         .setFile("./logs/localRegistry.reg");
        
        RegistryConfig registryConfigConsul = new RegistryConfig()
      	         .setProtocol("consul")
      	         .setAddress("127.0.0.1:8500");
        
        
        // 引用一个服务
        ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>()
                .setInterfaceId(HelloService.class.getName())
//              .setRegistry(registryConfigConsul)
              .setRegistry(registryConfigLocal)
                .setProtocol("bolt");
        
        // 拿到代理类
        HelloService service = consumerConfig.refer();
        
        // 发起调用
        while (true) {
            System.out.println(service.sayHello("world"));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
    }
}
